<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	findCompNm	= Request("findCompNm")
	findPrdNm		= Request("findPrdNm")
	stDate			= Request("stDate")
	endDate		= Request("endDate")
	findLotNo			= Request("findLotNo")
	types			= Request("type")
	findType			= Request("findType")
	findUserId		= Request("findUserId")

	If types = "" Then 
		types = "98"
	End If 
	
	SQLTitle = "-- ■■■■ 출하품 관리 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If findCompNm <> "" Then 
		addSql = " C.company LIKE '%" & findCompNm & "%' "
	End If 
	If findPrdNm <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " P.prdNm LIKE '%" & findPrdNm & "%' "
	End If 
	If stDate <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " A.workDt >= '" & stDate & "' "
	End If 
	If endDate <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " A.workDt <= '" & endDate & "' "
	End If 	
	If findLotNo <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & "  A.lotYear+A.lotNo LIKE '%" & findLotNo & "%' "
	End If 
	If findType <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " B.type='" & findType & "' "
	End If 
	If findUserId <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " U.userId='" & findUserId & "' "
	End If 

	If addSql <> "" Then addSql = " AND " & addSql END IF

	SQL = "SELECT C.company, A.workDt packDt, A.lotYear+A.lotNo+'-'+CAST(A.lotSubNo as varchar(4)) lotFullNo, A.rank, P.prdNm, A.goodQty, A.badQty, ISNULL(u.userNm,'&nbsp;') userNm, Z.billCd " & _
		  "FROM tblOrderResult A " & _
		  "		INNER JOIN tblOrder B ON A.lotYear=B.lotYear AND A.lotNo=B.lotNo AND A.lotSubNo=B.lotSubNo " & _
		  " 	LEFT JOIN (SELECT Z1.lotYear, Z1.lotNo, Z1.lotSubNo, Z1.rank, Z1.billCd FROM tblBizBill Z1 INNER JOIN tblIncome Z2 ON Z1.billCd=Z2.billCd WHERE Z2.flag='Y') Z ON A.lotYear=Z.lotYear AND A.lotNo=Z.lotNo AND A.lotSubNo=Z.lotSubNo AND A.rank=Z.rank " & _
		  "		LEFT JOIN tblCompany C ON B.compCd=C.compCd " & _
		  "		LEFT JOIN tblUser U ON A.userId=U.userId " & _
		  "		LEFT JOIN tblProduct P ON B.prdCd=P.prdCd " & _
		  "WHERE A.flag='Y' AND B.flag<>'N' AND ISNULL(A.workDt,'')<>'' AND A.type='" & types & "'" & addSql & _
		  "ORDER BY  workDt DESC"
		  

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<Packages>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
			
			If types = "98" Then 
				qty = FormatNumber(rs("goodQty"),0)
			Else
				qty = FormatNumber(rs("goodQty"),0) & "/" & FormatNumber(rs("badQty"),0)
			End If 
			billMemo = ""
 			if rs("billCd") > 0 then 
 				billMemo = "거래명세서 발급"
 			end if 
			Response.write "	<PackList>" & vbcrlf
				Call mkXMLNode("company", rs("company"), 2)
				Call mkXMLNode("packDt", rs("packDt"), 2)
				Call mkXMLNode("lotFullNo", rs("lotFullNo"), 2)
				Call mkXMLNode("prdNm", rs("prdNm"), 2)
				Call mkXMLNode("goodQty", qty, 2)
				Call mkXMLNode("userNm", rs("userNm"), 2)
				Call mkXMLNode("rank", rs("rank"), 2)
				Call mkXMLNode("billMemo",billMemo, 2)
				'Call mkXMLNode("working", rs("working"), 2)
			Response.write "	</PackList>" & vbcrlf

			ttlGood = ttlGood + CInt(rs("goodQty"))
			ttlBad = ttlBad + CInt(rs("badQty"))
		Rs.movenext
		Loop 
	End If
	
	If types = "98" Then 
		qty = FormatNumber(ttlGood,0)
	Else
		qty = FormatNumber(ttlGood,0) & "/" & FormatNumber(ttlBad,0)
	End If 
	Response.write "	<PackList>" & vbcrlf
		Call mkXMLNode("company", "<b>합 계</b>", 2)
		Call mkXMLNode("packDt", "&nbsp;", 2)
		Call mkXMLNode("lotFullNo", "&nbsp;", 2)
		Call mkXMLNode("prdNm", "&nbsp;", 2)
		Call mkXMLNode("goodQty", "<b>" & qty & "</b>", 2)
		Call mkXMLNode("userNm", "&nbsp;", 2)
	Response.write "	</PackList>" & vbcrlf
	Response.write "</Packages>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>